package com.yugao.fintech.antelope.auth.service.impl;

import com.yugao.fintech.antelope.auth.service.ThirdClientService;
import com.yugao.fintech.antelope.base.dynamic.AbstractClientProcess;
import com.yugao.fintech.antelope.base.dynamic.wx.WxMpWrapClient;
import com.yugao.fintech.antelope.base.model.enums.ConfigDefineEnum;
import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ThirdClientServiceImpl implements ThirdClientService {

    @Override
    public WxJsapiSignature createWxMpJsapiSignature(String url) {
        WxMpWrapClient dynamicClient = (WxMpWrapClient) AbstractClientProcess.getDynamicClient(ConfigDefineEnum.WX_MP);
        try {
            return dynamicClient.getService().createJsapiSignature(url);
        } catch (WxErrorException e) {
            throw new BizException("获取签名失败-" + e.getError().getErrorMsg());
        }
    }
}
